﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;
using System.Security.Cryptography;

public partial class controls_admin_FAQsEdit : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            try
            {
                base.bindDDL(ddlCategories, BO_portal_categories.InsideContent(5, "FAQs"), "FULL_CATEGORY_NAME", "CATEGORY_ID");
                loadData();
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message);
            }
        }
    }

    private void loadData()
    {
        DataRow drow = BO_portal_articles.Search(Id).Rows[0];
        ddlCategories.SelectedValue = drow["CATEGORY_ID"].ToString();
        txtFULL_ARTICLE_TITLE.Text = drow["FULL_ARTICLE_TITLE"].ToString();
        ckContent.Text = drow["ARTICLE_DETAIL"].ToString();
        txtEmail.Text = drow["SHORT_ARTICLE_DESCRIPTION"].ToString();
        txtName.Text = drow["CREATED_BY"].ToString();
        txtOrder.Text = drow["ORDER_DISPLAY"].ToString();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            DataRow drow = BO_portal_articles.Search(Id).Rows[0];
            string default_string = string.Empty;
            string filename = drow["THUMB_IMG"].ToString();
            filename = string.Empty;// base.Upload("articles", filename, fulTHUMB_IMG, divMessage, false);
            int category_id = Convert.ToInt32(ddlCategories.SelectedValue);
            int status = 1;
            string tags = string.Empty;//txtTags.Text.Trim();
            string title = txtFULL_ARTICLE_TITLE.Text.Trim();
            string full_article_description = string.Empty;//txtFULL_ARTICLE_DESCRIPTION.Text.Trim();
            string details = ckContent.Text;
            bool displayOnHome = true;// cboDisplay.Checked;
            bool hot = false;// cboHot.Checked;
            int sort_display = Convert.ToInt32(txtOrder.Text.Trim());
            string m_key = string.Empty;//txtMetaKeyword.Text.Trim();
            string m_desc = string.Empty;//txtMetaDescription.Text.Trim();
            string code = string.Empty;//drow["ARTICLE_CODE"].ToString();
            string strResult = BO_portal_articles.Update(Id, category_id, 1, code,
                             default_string, filename, string.Empty, string.Empty, title, string.Empty, txtEmail.Text.Trim()
                             , string.Empty, full_article_description, string.Empty,
                             details, string.Empty, m_key, m_desc, tags, Convert.ToInt32(drow["TOTAL_DOWNLOAD"]),
                            Convert.ToInt32(drow["TOTAL_VOTE"]), Convert.ToInt32(drow["TOTAL_COMMENT"]), Convert.ToInt32(drow["TOTAL_VIEW"]),
                            displayOnHome, hot, sort_display, sort_display, Convert.ToDateTime(drow["PUBLISHED_DATE"]), Convert.ToDateTime(drow["APPROVED_DATE"]),
                            Administrator.USER_NAME, Convert.ToDateTime(drow["CREATED_DATE"]), txtName.Text.Trim(), DateTime.Now, Administrator.USER_NAME, status);
            if (strResult != "0")
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Cập nhật thành công!");
                Response.Redirect("default.aspx?control=faqs&category_id=" + ddlCategories.SelectedValue + "&" + Request["pager"].ToString() + "=" + Request[Request["pager"].ToString()].ToString() + "&keyword=" + Keyword);
            }
            else
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Có lỗi trong quá trình xử lý! Đăng tin thất bại!");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message);
        }
    }
}
